#include <stdio.h>
void intToString(int n, char str[]);
void intToStringRecursive(int n, char str[], int *index);
int main() {
    int num;
    char str[20]; 

    printf("请输入一个整数: ");
    scanf("%d", &num);

    intToString(num, str);

    printf("转换后的字符串为: %s\n", str);

    return 0;
}

void intToString(int n, char str[]) {
    int index = 0;
    if (n == 0) {
        str[0] = '0';
        str[1] = '\0';
        return;
    }
    if (n < 0) {
        str[0] = '-';
        index = 1;
        n = -n;
    }

    intToStringRecursive(n, str, &index);
    str[index] = '\0'; 
}

void intToStringRecursive(int n, char str[], int *index) {
    if (n <= 0)
        return;

    int digit = n % 10;              
    intToStringRecursive(n / 10, str, index);

    str[*index] = '0' + digit;       
    (*index)++;
}
